package com.yuxin.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.DateFormat;

/**
 * @author zehui.zeng
 * @date 13-3-18 下午2:42
 */
public class DateUtil {
    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
    public static final String DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";

    /*** 日期转字符串 ***/
    public static String fomatDate(Date date,String format){
         DateFormat dateFormat = null;
         if(format == null || format.length() == 0){
             format = DEFAULT_DATE_PATTERN;
         }
         dateFormat = new SimpleDateFormat(format);
         return dateFormat.format(date);
    }

    /*** 字符串转日期 ***/
    public static Date parseDate(String date,String format) throws ParseException {
        DateFormat dateFormat = null;
        if(format == null || format.length() == 0){
            format = DEFAULT_DATE_PATTERN;
        }
        dateFormat = new SimpleDateFormat(format);
        return dateFormat.parse(date);
    }
}
